Imports System.Runtime.Serialization
Imports System.Runtime.Versioning
'Namespace cv2.File
''' <summary>
''' BikiRom Variables (internal use only)
''' </summary>
''' <remarks></remarks>
<Serializable()> Friend Class BVar
    Private m_name As String = ""
    Private m_description As BikDescription = Nothing

    <OptionalField(VersionAdded:=2)> _
    Private m_txtValue As String = ""

    <OptionalField(VersionAdded:=2)> _
    Private m_ValueType As bvarType = bvarType.BV_DBL
    <OptionalField(VersionAdded:=2)> _
    Private m_CompileType As _CompileType = _CompileType.CT_NONE
    <OptionalField(VersionAdded:=2)> _
    Private m_SearchKey As String = ""

    Friend Enum bvarType As Byte
        BV_DBL = 0
        BV_TXT = 1
    End Enum

    Friend Enum _CompileType As Byte
        CT_NONE = 0
        CT_ARATHMATIC_UNIT = 1
        CT_TRIGGER = 2
    End Enum

    Private m_value As Double = 0
    Private m_next As BVar = Nothing

    Friend Sub New(ByVal Name_ As String, ByVal Desc_ As BikDescription)
        m_name = Trim(Name_)
        m_description = Desc_
    End Sub
    Friend Sub New(ByVal Name_ As String, ByVal Desc_ As BikDescription, ByVal Value As Double)
        Me.New(Name_, Desc_)
        m_value = Value
    End Sub
    Friend Sub New(ByVal Name_ As String, ByVal Description As String, ByVal ValType As bvarType, ByVal Value As String, ByVal Key As String)
        Me.New(Name_, New BikDescription(Description))
        m_ValueType = ValType
        If ValType = bvarType.BV_TXT Then
            m_txtValue = Value
        Else
            m_value = Val(Value)
        End If
    End Sub

    Friend Function Clone() As BVar
        Dim objNew As New BVar(m_name, m_description, m_value)
        objNew.m_txtValue = m_txtValue
        objNew.m_ValueType = m_ValueType
        Return objNew
    End Function

    Friend Sub addNode(ByRef node As BVar)
        If IsNothing(m_next) Then
            If Trim(LCase(node.Name())) <> Trim(LCase(m_name)) Or LCase(node.Name) = "note" Then
                m_next = node
            End If
        Else
            If Trim(LCase(node.Name())) <> Trim(LCase(m_name)) Or LCase(node.Name) = "note" Then
                m_next.addNode(node)
            End If
        End If
    End Sub

    Public Property Name() As String
        Get
            Return m_name
        End Get
        Set(ByVal value As String)
            m_name = value
        End Set
    End Property
    Public Property Description() As BikDescription
        Get
            Return m_description
        End Get
        Set(ByVal value As BikDescription)
            m_description = value
        End Set
    End Property
    Public Property Value() As Double
        Get
            Return m_value
        End Get
        Set(ByVal value As Double)
            m_value = value
        End Set
    End Property
    Public Property ValueTxt() As String
        Get
            Return m_txtValue
        End Get
        Set(ByVal value As String)
            m_txtValue = value
        End Set
    End Property

    Friend Sub setNext(ByRef nextNode As BVar)
        m_next = nextNode
    End Sub
    Friend Function getnext() As BVar
        Return m_next
    End Function
    Friend Function count() As Integer
        Dim intReturn As Integer
        intReturn = 1
        If (Not IsNothing(m_next)) Then
            intReturn += m_next.count
        End If
        Return (intReturn)
    End Function

    Friend ReadOnly Property ValueType() As bvarType
        Get
            Return m_ValueType
        End Get
    End Property
    Friend ReadOnly Property CompileType() As _CompileType
        Get
            Return m_CompileType
        End Get
    End Property
    Friend ReadOnly Property getKey() As String
        Get
            Return m_SearchKey
        End Get
    End Property
    Friend Sub setKey(ByVal str As String)
        m_SearchKey = str
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class
